package cn.eric.bookstore.utils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class AuthUtil implements cn.eric.framework.auth.utils.auth.AuthUtil {
    @Resource
    private String httpHeaderToken;

    @Override
    public String getUid(HttpSession session, HttpServletRequest request) {
        return null;
    }

    public String getUid(HttpServletRequest request) {
        return getUid(null, request);
    }

    /**
     * 判断给出的UID是否是当前token的持有者
     *
     * @param request   请求
     * @param targetUid 目标uid
     * @return 判断结果
     */
    public boolean isSelf(HttpServletRequest request, String targetUid) {
        return targetUid != null && targetUid.equals(getUid(request));
    }

    @Override
    public String login(String uid, HttpSession session, HttpServletRequest request) {
        return null;
    }

    /**
     * 对明文密码加密
     *
     * @param pwd 明文密码
     * @return 加密过后的密码
     */
    public static String encryptPwd(String pwd) {
        return pwd;
    }

    /**
     * 比较明文密码和加密后的密码是否匹配
     *
     * @param originPwd    明文密码
     * @param encryptedPwd 加密后的密码
     * @return 是否匹配
     */
    public static boolean isPwdCorrect(String originPwd, String encryptedPwd) {
        return encryptedPwd.equals(AuthUtil.encryptPwd(originPwd));
    }
}
